11 April 2018

About me

  • Lead Data Scientist at Quantiful
  • Tool builder
  • Co-organiser Auckland R Meetup Group
  • Educator

Overview

  • Example application
  • Why use R for web apps?
  • Visualisations and widgets
  • Reusability
  • Collaboration
  • Data backend
  • Production

Example Shiny app – UFOs anyone?

Why use R for web apps???

Two extremes to develop an app

Off-the-shelf dashboards

  • PowerBI, Tableau, QuickSight, …
  • Easy to create, publish and share
  • Rapid development
  • Limited customisation
  • No version control
  • Definition of charts buried in UI
  • No automatic testing

Custom web app

  • Angular, ReactJS, Ember, …
  • Engineering control
  • Flexibility
  • Learning curve
  • Costly development
  • Development spread across multiple teams

Meet Shiny

  • "Build interactive web apps straight from R"
  • Code based – version control, easy to collaborate, changelogs, clear chart definitions, easy search for help
  • No deep HTML/CSS/JS knowledge required
  • Reasonable flexibility
  • Rapid development
  • Scalability
  • Performance
  • Requires deployment and security

Visualisations and widgets

Charts

  • highcharter – fancy charts with animations and all
  • plotly – fast rendering scientific charting engine
  • d3wordcloud – fancy word clouds

Maps and tables

  • leaflet – clickable interactive maps
  • DT – clickable tables with filtering, pagination, sorting

Visualisations and widgets (2)

Reusability

Shiny modules

  • Break complex logic into separate modules
  • Reusable, independent components
  • Package and distribute modules for other authors

Module example in 35 lines of code

Collaboration

  • Shiny app = R code
  • Effecient collaboration via version controlled code repository (e.g. GIT)
  • Packrat – Package management for R

Data backends

  • R can access almost any data source
  • Local files – text (readr), JSON (jsonlite), Excel (readxl), spatial (sf)
  • RDBS – convenient DB connection management (pool) and access (dbplyr)
  • NoSQL – MongoDB (mongolite), ElasticSearch (elastic), Redis (redux), Spark (sparklyr)
  • Data services – Google Sheets (googlesheets), Dropbox (rdrop2), AWS S3 (aws.s3)
  • REST APIs – generic (httr), Twitter (rtweet), Google Analytics (googleAnalyticsR), …

Example – Data streaming in Shiny

Data backends – ElasticSearch

  • Distributed, RESTful search and analytics engine
  • Stores schema-free JSON documents
  • Near real-time search and retrieval
  • Reasonably featured JSON based query language (boolean filters and aggregations, limited join capability)
  • Package elastic provides interface from R
  • Package jqr provides convenient and fast conversion of nested JSON response into dataframe

Production

Deployment – shinyapps.io

"Deploy your Shiny applications on the Web in minutes"

  • Push-button solution from RStudio
  • Free and paid tiers available
  • Paid tier offers enterprise features
  • Convenient interface to tune deployment and see usage stats
  • Loading times of deployed app
  • Advanced features can be pricy
  • No control over location of deployment

Deployment – ShinyProxy

"Deploy Shiny apps in an enterprise context"

  • Enterprise features: authentication, scalability (wihtin reason), control over memory and CPU
  • Docker based – Shiny app installed into docker container that spins up on user request
  • Java Spring responsible for user authentication and container spin-up

Security – ShinyProxy + SSL

  • Web server, e.g. nginx, responsible for SSL encryption
  • ShinyProxy responsible for user authentication
  • Shiny container responsible for serving Shiny app

Want to learn more?

Data Science Academy

www.datascienceacademy.co.nz